extends "../cTDW/cTDW.gd"
func _info():
	pass

func _connect():
	._connect()


var norcnt:int = 0
var tlv = 0
var nlv = 0
var laicha = null
var spw1 = 10
var spw2 = 1.12

func _extInit():
	._extInit()
	#chaName = "圣剑客·Lv[0]"
	
	lv = 4
	attCoe.atkRan = 2
	attCoe.atk = 36 / 8.5 * 2 / 4
	attCoe.maxHp = 700 / 112.5 / 4
	attAdd.spd -= 0.1
	addCdSkill("sqs",5)
	addCdSkill("sqs1",5)
	addSkillTxt("圣骑队：召唤一个士兵到身边[cd:5秒]")
	addSkillTxt("圣骑队·改：【圣骑队】改为召唤两个士兵到身边，cd增加3秒【攻击增加<10+技能等级*5%自身攻击>点，身边没有位置则召唤失败】[color=#666666][未解锁][/color]")
	addSkillTxt("神圣充能：普攻每击中一次，伤害增加<12+技能等级>%【乘法；切换目标则重新计算增伤】[color=#666666][未解锁][/color]")
	addSkillTxt("战争之马：[主动]使当前敌人附加1层<眩晕>[cd:5秒][被动]攻速提升<5+技能等级>%；闪避提升<10+技能等级>%【开始战斗起效】[color=#666666][未解锁][/color]")
	addSkillTxt("[color=red]Tips:杀人会获得经验，战斗结束后会计算经验并升级;升级获得的属性和解锁的技能及等级全局有效")
	nlv = 0
	lvup()
	if skill3unlock:
		skillunlock(3)
	if skill2unlock:
		skillunlock(2)
	if skill1unlock:
		skillunlock(1)

func _onBattleStart():
	._onBattleStart()
	
	
	if skill1unlock:
		getSkill("sqs").cd = 8
	norcnt = 0
	if skill3unlock:
		self.addBuff(BF.new(1,skill3lv))
	if sys.test:
		lvup()
		if !skill3unlock:
			#print("unlock3")
			skillunlock(3)

func _castCdSkill(id):
	._castCdSkill(id)
	if id == "sqs":
		cst("圣骑队","000000",position)
		var n = 1
		if skill1unlock:n = 2
		for i in range(n):
			var ncha = newChara("cTDW",self.cell)
			if ncha && skill1unlock:
				skill1up()
				ncha.attInfo.atk += spw1
				ncha.upAtt()
	if id == "sqs1" && skill3unlock && aiCha:
		cst("战争之马","000000",position)
		aiCha.addBuff(ctrl.b_xuanyun.new(1))

func _onAtkChara(atkinfo):
	if atkinfo.atkType == Chara.AtkType.NORMAL && !atkinfo.isMiss && atkinfo.hitCha != self && atkinfo.atkCha == self:
		if skill2unlock:
			if atkinfo.hitCha != laicha:
				laicha = atkinfo.hitCha
				norcnt = 0
			else:
				norcnt += 1
			skill2up()
			atkinfo.hurtVal *= pow(spw2,norcnt)
	._onAtkChara(atkinfo)
#战后计算经验
func _onBattleEnd():
	._onBattleEnd()
	yield(reTimer(0.01),"timeout")
	lvup()
	upAtt()
#升级改名改等级
func lvup():

	#if chaName.find("Lv[") == -1:
	#	nlv = 0
	#else:
	#	nlv = int(chaName.right(chaName.find("[")).left(2))
		
	if killNum >= 2:
		tlv = 1
	var e = 2
	var k = 3
	while(killNum >= e + k):
		tlv += 1
		e = e + k
		k += 1
	if sys.test:tlv = nlv + 1
	tlv = min(18,tlv)
	if tlv > nlv:
		upattadd(tlv,nlv)
		nlv = tlv
	chaName = "圣骑士·Lv[" + str(nlv) + "]"
#升级修改属性
func upattadd(tlv,nlv):
	attAdd.atk += (tlv - nlv) * 7.7
	attAdd.maxHp += (tlv - nlv) * 70
	attAdd.def += (tlv - nlv) * 7
	attAdd.mgiDef += (tlv - nlv) * 7
	attAdd.spd += (tlv - nlv) * 0.02
	attAdd.cd += (tlv - nlv) * 0.02
	healCha(self,(tlv - nlv) * 20)
#修改技能1系数
func skill1up():
	spw1 = 10 + skill1lv * 0.05 * att.atk
#修改技能2系数
func skill2up():
	spw2 = (1.12 + skill2lv * 0.01)
#技能3buff
class BF:
	extends Buff
	var canremove:bool = false
	func _init(lv,slv):
		attInit()
		life = 100000
		att.spd = 0.05 + slv * 0.01
		att.dod = 0.1 + slv * 0.01